package com.yoyo.yoyoplat.base;

import com.yoyo.yoyoplat.util.ToutiaoUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class ApiConstants {
    public static final String GET = "GET";
    public static final String POST = "POST";
    public static final String UTF_8 = "UTF-8";
    //    正式环境:
    private static final String BASE_URL = "http://api.yoyoad.cn/sdk-ad-api/";
    //    测试环境;
//    private static final String BASE_URL = "http://testapi.yoyoad.cn:8081/sdk-ad-api/";

    public static final String getData = BASE_URL + "router/V100/getData";
    public static final String dotByPnames = BASE_URL + "router/V100/dotByPnames";

    public static String Real_IP;

    public static final String AS = "as";
    public static final String CP = "cp";

    private static final String KEY = "DowCnWHC";
    private static final String TOKEN = "5043caa85f2547d999340faece8d9621";
    private static final int IMP_ID = 10001;

    /*  ------- 错误码 --------  */
    //成功
    public static final String SUCCESS = "0";
    //参数异常
    public static final String ILLEGAL_ARGUMENT_EXCEPTION = "1";
    //加密参数异常
    public static final String ENCRYPTION_EXCEPTION = "2";
    //系统繁忙
    public static final String NET_EXCEPTION = "3";
    //业务错误
    public static final String BUSINESS_EXCEPTION = "4";
    //⾮法key(key 从下发开始, 其生命周期只有2 个⼩时, 超出这个期间将过期失效)
    public static final String ILLEGAL_KEY_EXCEPTION = "5";

    /*  ------- 业务类型 --------  */
    //Banner(⼤图)
    public static final int BUSINESS_TYPE_BANNER = 1;
    //icon(⼩图)
    public static final int BUSINESS_TYPE_ICON = 2;
    //信息流(图文)
    public static final int BUSINESS_TYPE_DRAW = 3;
    //文字
    public static final int BUSINESS_TYPE_TEXT = 4;
    //原生视频
    public static final int BUSINESS_TYPE_VIDEO = 5;
    //激励视频
    public static final int BUSINESS_TYPE_REWARD_VIDEO = 6;
    //开屏
    public static final int BUSINESS_TYPE_SPLASH = 7;

    /*  ------- 基本 --------  */
    //广告创意展示的时候触发
    public static final int TK_IMP = 10000;
    //广告点击的时候触发
    public static final int TK_CLK = 10001;

    /*  ------- app --------  */
    //广告包开始下载的时候触发
    public static final int TK_DLE_START = 10002;
    //广告包下载完成的时候
    public static final int TK_DLE_SUCCESS = 10003;
    //进入系统安装页面并且点击安装之后
    public static final int TK_INSTALL_START = 10004;
    //监听到系统安装完成广播之后
    public static final int TK_INSTALL_SUCCESS = 10005;

    /*  ------- 视频 --------  */
    //视频播放开始
    public static final int TK_VIDEO_START = 10006;
    //视频播放⾄25%时
    public static final int TK_VIDEO_FIRST_QUARTILE = 10007;
    //视频播放50%时
    public static final int TK_VIDEO_MIDPOINT = 10008;
    //视频播放⾄75%时
    public static final int TK_VIDEO_THIRD_QUARTILE = 10009;
    //视频播放完成时
    public static final int TK_VIDEO_END = 10010;
    //视频静⾳时上报
    public static final int TK_VIDEO_MUTE = 10011;
    //跳过视频时
    public static final int TK_VIDEO_SKIP = 10012;
    //关闭视频时
    public static final int TK_VIDEO_CLOSE = 10013;

    public static final String ACTION_DLE_START = "com.dollkey.hdownload.DownLoadNormalService.action.ACTION_DLE_START";
    public static final String ACTION_DLE_SUCCESS = "com.dollkey.hdownload.DownLoadNormalService.action.ACTION_DLE_SUCCESS";
    public static final String ACTION_INSTALL_START = "com.dollkey.hdownload.DownLoadNormalService.action.ACTION_INSTALL_START";

    private static String getNonce() {
        return String.valueOf(100000 + new Random().nextInt(50000));
    }

    private static String getSign(String timestamp) {
        return ToutiaoUtil.getMD5("timestamp=".concat(timestamp)
                .concat("&token=").concat(TOKEN).concat("&").concat(KEY)).toUpperCase();
    }

    public static Map<String, String> getUrlMap() {
        Map<String, String> map = new HashMap<>();
        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
        map.put("token", TOKEN);
        map.put("timestamp", timestamp);
        map.put("nonce", getNonce());
        map.put("sign", getSign(timestamp));
        return map;
    }
}
